//
//  NRWCarListCell.m
//  NRWMall
//
//  Created by 邢毅 on 2018/5/22.
//  Copyright © 2018年 com.anpxd. All rights reserved.
//

#import "NRWCarListCell.h"
#import "NRWBuyCarListRectModel.h"

@interface NRWCarListCell()
///启辕认证logo
@property (strong, nonatomic) UIImageView *certifylogoImageView;
///车辆图片
@property (strong, nonatomic) UIImageView *carIconImageView;
///车辆名称
@property (strong, nonatomic) UILabel *carTitleLabel;
///市场  公里数
@property (strong, nonatomic) UILabel *detailLabel;
///价格
@property (strong, nonatomic) UILabel *priceLabel;
///价格单位
@property (strong, nonatomic) UILabel *priceUnitLabel;
///时间
@property (strong, nonatomic) UILabel *timeLabel;

@end

@implementation NRWCarListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.separatorInset = UIEdgeInsetsZero;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
		self.backgroundColor = self.contentView.backgroundColor = [UIColor whiteColor];
		self.opaque = self.contentView.opaque = YES;
        [self setupUI];
	
    }
    return self;
}
//buycar_defaut 占位图片
- (void)setupUI {
    
    self.certifylogoImageView = DPImageView();
	if (self.certifylogoImageView.image == nil) {
		self.certifylogoImageView.image = getImage(@"buycar_certify");
	}
    
    self.carIconImageView = DPImageView().setBackgroundColor([UIColor whiteColor]);
	self.carIconImageView.opaque = YES;
    
    self.carTitleLabel = DPLabel().setTextColor(getColor(@"#323232")).setFont(getThemeFont(14));
    self.carTitleLabel.numberOfLines = 2;
	self.carTitleLabel.backgroundColor = [UIColor whiteColor];
	self.carTitleLabel.opaque = YES;
    
    self.detailLabel = DPLabel().setTextColor(getColor(@"#989898")).setFont(getThemeFont(11));
	self.detailLabel.backgroundColor = [UIColor whiteColor];
	self.detailLabel.opaque = YES;
    
    self.priceLabel = DPLabel().setTextColor(mainColor()).setFont(getThemeFont(22));
	self.priceLabel.backgroundColor = [UIColor whiteColor];
	self.priceLabel.opaque = YES;
	
	self.priceUnitLabel = DPLabel().setTextColor(mainColor()).setFont(getThemeFont(13)).setText(@"万");
	self.priceUnitLabel.backgroundColor = [UIColor whiteColor];
	self.priceUnitLabel.opaque = YES;
    
    self.timeLabel = DPLabel().setTextColor(getColor(@"#CCCCCC")).setFont(getThemeFont(11));
	self.timeLabel.backgroundColor = [UIColor whiteColor];
	self.timeLabel.opaque = YES;
    
    self.contentView
    .addSubview(self.carIconImageView)
    .addSubview(self.carTitleLabel)
    .addSubview(self.detailLabel)
    .addSubview(self.timeLabel)
    .addSubview(self.priceLabel)
	.addSubview(self.priceUnitLabel);
    
    self.carIconImageView.addSubview(self.certifylogoImageView);
}

- (void)setCarFrameModel:(NRWBuyCarListRectModel *)carFrameModel {
	
	_carFrameModel = carFrameModel;
	
	self.certifylogoImageView.frame = carFrameModel.certifylogoImageViewFrame;
	self.carIconImageView.frame = carFrameModel.carIconImageViewFrame;
	self.carTitleLabel.frame = carFrameModel.carTitleLabelFrame;
	self.detailLabel.frame = carFrameModel.detailLabelFrame;
	self.priceLabel.frame = carFrameModel.priceLabelFrame;
	self.priceUnitLabel.frame = carFrameModel.priceUnitLabelFrame;
	self.timeLabel.frame = carFrameModel.timeLabelFrame;
	
	[self.carIconImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@.r_%dxh_%d", imageApi(), carFrameModel.dataModel.carImageUrl, (int)(UIScreen.mainScreen.scale * 120), (int)(UIScreen.mainScreen.scale) * 80]] placeholderImage:getImage(@"List_defualt")];
	
	self.certifylogoImageView.hidden = !carFrameModel.dataModel.carAuthState;
	
	self.carTitleLabel.text = carFrameModel.dataModel.carTitle;
	
	self.detailLabel.text = carFrameModel.detailStr;
	
	self.timeLabel.text = carFrameModel.dataModel.market.city.cityName;
	
	if (carFrameModel.dataModel.carRetailPrice == 0) {
		self.priceLabel.font = getThemeFont(16);
		self.priceLabel.text = carFrameModel.priceStr;
		self.priceUnitLabel.hidden = YES;
	} else {
		self.priceLabel.font = getBoldFont(22);
		self.priceLabel.text = self.priceLabel.text = carFrameModel.priceStr;
		self.priceUnitLabel.hidden = NO;

	}
}

@end
